uniform sampler1D ColorIndex;
uniform float CETX;
uniform float CETY;
const int maxiterations = 32;
const float scaling = 160.0;

void main(void)
{
  float xpos = gl_FragCoord.x / scaling - 1.6;
  float ypos = gl_FragCoord.y / scaling - 1.6;
  float xquad = pow( xpos, 2.0 );
  float yquad = pow( ypos, 2.0 );
  int n = -1;
  int loopcount = 0;
  while ( loopcount <= maxiterations )
    {
      ypos = 2.0 * xpos * ypos + CETY;
      xpos = xquad - yquad + CETX;
      xquad = pow( xpos, 2.0 );
      yquad = pow( ypos, 2.0 );
      n++;
      float tempstorage = xquad + yquad;
      if ( tempstorage > 4.0 ) loopcount = maxiterations;
      loopcount++;
    }
  float color = float( n ) / float( maxiterations );
  gl_FragColor = texture1D( ColorIndex, finalcolor );
  // for Greyscale use: gl_FragColor = vec4(finalcolor, finalcolor, finalcolor,0.0);
}